<template>
	<view class="content">
		<view class="title">
			子组件B
		</view>
		<view class="b-box">
			组件A传进来的值：
			<text class="intent-text-box">{{res}}</text>
		</view>
		<view class="b-box">
			<view class="b-box-inner">

				<text>回传值：</text>
				<input type="text" v-model="callbackValue" style="color: yellow; background-color: aqua;"></input>
			</view>
			<button @click="sendOutside()" size="mini" type="primary">回传</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "componentB",
		data() {
			return {
				res: '',
				callbackValue: '' // 初始回传值
			};
		},
		created() {

			uni.$on('sendToCompB', (val) => {
				this.res = val;
			});
		},
		methods: {
			sendOutside() {

				this.$emit('callBackFun', this.callbackValue);
			}
		}
	}
</script>

<style>
	.content {
		padding: 20rpx;
		background-color: #4CD964;
		margin-top: 20rpx;
	}

	.title {
		font-size: 50rpx;

		margin-bottom: 10rpx;
		text-align: center;
	}

	.b-box {
		margin: 10rpx;

	}

	.intent-text-box {
		background-color: rgb(76, 217, 100);
		color: #fff;
		padding: 2rpx 10rpx;
		border-radius: 4rpx;
	}
	
	.b-box-inner{
		display: flex;
		margin-bottom: 10rpx;
	}
</style>